package com.huawang.mdesign.model.service.controller;

import com.huawang.mdesign.model.service.dto.*;
import com.huawang.mdesign.model.service.inter.ActivityService;
import com.huawang.mdesign.model.service.vo.BaseResponse;
import com.huawang.mdesign.model.service.vo.selectelementitem.SelectElementItem;
import com.huawang.business.constants.ParamErrorConstants;
import com.huawang.business.util.ValidateDataUtil;
import com.huawang.business.vo.ModelResultVo;
import com.huawang.business.vo.PinTypeVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

@Tag(name = "活动")
@RestController
@RequestMapping("/activity")
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    @Operation(summary = "活动可创建输入栓类型")
    @GetMapping("/queryInputPinTypes")
    public BaseResponse<List<PinTypeVo>> queryInputPinTypes(@NotEmpty(message = ParamErrorConstants.NO_PROJECT_ID) String projectId,
                                                            @NotEmpty(message = ParamErrorConstants.NO_INSTANCE_ID) String instanceId) {
        return BaseResponse.success(activityService.queryInputPinTypes(projectId, instanceId));
    }

    @Operation(summary = "活动可创建输出栓类型")
    @GetMapping("/queryOutputPinTypes")
    public BaseResponse<List<PinTypeVo>> queryOutputPinTypes(@NotEmpty(message = ParamErrorConstants.NO_PROJECT_ID) String projectId,
                                                             @NotEmpty(message = ParamErrorConstants.NO_INSTANCE_ID) String instanceId) {
        return BaseResponse.success(activityService.queryOutputPinTypes(projectId, instanceId));
    }

    @Operation(summary = "快速创建活动图")
    @PostMapping("/quickCreateActivityDiagram")
    public BaseResponse<ModelResultVo> quickCreateActivityDiagram(@RequestBody QuickCreateActivityDiagramDTO quickCreateActivityDiagramDto) {
        ValidateDataUtil.isNotEmpty(quickCreateActivityDiagramDto.getProjectId());
        ValidateDataUtil.isNotNull(quickCreateActivityDiagramDto.getType());
        ValidateDataUtil.isNotEmpty(quickCreateActivityDiagramDto.getMetaclass());
        ValidateDataUtil.isNotEmpty(quickCreateActivityDiagramDto.getInstanceId());
        return BaseResponse.success(activityService.quickCreateActivityDiagram(quickCreateActivityDiagramDto));
    }

    @Operation(summary = "查询活动图上未显示的活动参数节点")
    @PostMapping("/queryActivityParameterNodes")
    public BaseResponse<List<SelectElementItem>> queryActivityParameterNodes(@RequestBody QueryActivityParameterNodeDTO queryActivityParameterNodeDto) {
        ValidateDataUtil.isNotEmpty(queryActivityParameterNodeDto.getProjectId());
        ValidateDataUtil.isNotEmpty(queryActivityParameterNodeDto.getInstanceId());
        return BaseResponse.success(activityService.queryActivityParameterNodes(queryActivityParameterNodeDto.getProjectId(),
                queryActivityParameterNodeDto.getInstanceId(), queryActivityParameterNodeDto.getActivityParameterNodeIds()));
    }

    @Operation(summary = "查询活动参数对应的活动参数节点")
    @GetMapping("/queryParameterCorrespondingNode")
    public BaseResponse<String> queryParameterCorrespondingNode(@NotNull(message = ParamErrorConstants.NO_PROJECT_ID) String projectId,
                                                                @NotNull(message = ParamErrorConstants.NO_INSTANCE_ID) String instanceId) {
        return BaseResponse.success(activityService.queryParameterCorrespondingNode(projectId, instanceId));
    }

    @Operation(summary = "新建动作的同时自动创建活动")
    @PostMapping("/createActionWithActivity")
    public BaseResponse<ModelResultVo> createActionWithActivity(@RequestBody CreateActionWithActivityDTO createActionWithActivityDto) {
        ValidateDataUtil.isNotEmpty(createActionWithActivityDto.getProjectId());
        return BaseResponse.success(activityService.createActionWithActivity(createActionWithActivityDto));
    }


    @Operation(summary = "通过拖拽创建图元")
    @PostMapping("/createEntityByDrag")
    public BaseResponse<ModelResultVo> createEntityByDrag(@RequestBody CreateEntityByDragDTO createActionWithActivityDto) {
        ValidateDataUtil.isNotEmpty(createActionWithActivityDto.getProjectId());
        return BaseResponse.success(activityService.createEntityByDrag(createActionWithActivityDto));
    }

    @Operation(summary = "创建飞行时序图指令动作")
    @PostMapping("/createCommandAction")
    public BaseResponse<ModelResultVo> createCommandAction(@RequestBody CreateCommandActionDTO dto) {
        ValidateDataUtil.isNotEmpty(dto.getProjectId());
        return BaseResponse.success(activityService.createCommandAction(dto));
    }

    @Operation(summary = "查询要创建的泳道的代表")
    @GetMapping("/queryRepresentsOfSwimLines")
    public BaseResponse<List<String>> queryRepresentsOfSwimLines(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId,
                                                                 @NotBlank(message = ParamErrorConstants.NO_INSTANCE_ID) String instanceId) {
        return BaseResponse.success(activityService.queryRepresentsOfSwimLines(projectId, instanceId));
    }

    @Operation(summary = "根据分配模式更改分配目标")
    @PostMapping("/updateAllocatedToByMode")
    public BaseResponse<ModelResultVo> updateAllocatedToByMode(@RequestBody UpdateAllocatedToByModeDTO dto) {
        return BaseResponse.success(activityService.updateAllocatedToByMode(dto));
    }

    @Operation(summary = "删除交叉泳道，泳道内图元 移动其他泳道内")
    @PostMapping("/deleteAllocateActionPartition")
    public BaseResponse<ModelResultVo> deleteAllocateActivityPartition(@RequestBody DeleteAllocateActivityPartitionDTO dto) {
        return BaseResponse.success(activityService.deleteAllocateActivityPartition(dto));
    }
}
